package geektime.spring.springbucks.controller;

import geektime.spring.springbucks.service.CoffeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/coffee")
@Slf4j
public class CoffeeController {
    @Autowired
    private CoffeeService coffeeService;

    @PostMapping(path = "/getCoffeeByNameForJson", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object getCoffeeByNameForJson(@RequestParam(value = "coffeeName", defaultValue = "") String coffeeName) {
        return coffeeService.getCoffeesByCoffeeName(coffeeName);
    }

    @PostMapping(path = "/getCoffeeByNameForXml", produces = MediaType.APPLICATION_XML_VALUE)
    public Object getCoffeeByNameForXml(@RequestParam(value = "coffeeName", defaultValue = "") String coffeeName) {
        return coffeeService.getCoffeesByCoffeeName(coffeeName);
    }
}
